<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>  
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    <div class="easyui-layout" fit="true" style="height:200px;">
    	<div data-options="region:'east',split:true" title="监控台" style="width:180px;">
			<ul class="easyui-tree" id="stats"></ul>
		</div>
		
		<div id="content" region="center" title="发送信息" style="padding:20px;">
		
		
    	<table id="dg" title="微信号列表" style="width:auto;height:520px" data-options="
    				rownumbers:true,
    				singleSelect:true,
    				autoRowHeight:false,
    				pagination:true,
    				pageSize:20">
    		<thead>
    			<tr style="width:100%">
    				<th  field="id" width="100">编号</th>
    				<th  field="Uin" width="200">微信号</th>
    				<th  field="NickName" width="250">微信别名</th>
    				<th  field="loginTime" width="250" align="right">登陆时间</th>
    				<th  field="note" width="110" align="right">状态</th>
    			</tr>
    		</thead>
    	</table>
    	</div>
    	</div>
    	<script>
            function getData(json){
    
            var rows = [];
            for(var i = 0;i<json.length;i++){
                
                rows.push({
                    id: json[i].id,
                    loginTime:json[i].loginTime,
                    Uin :json[i].Uin,
                    NickName: json[i].NickName,
                    note:0
                });
            }
            return rows;
        }
    		
    		function pagerFilter(data){
    			if (typeof data.length == 'number' && typeof data.splice == 'function'){	// is array
    				data = {
    					total: data.length,
    					rows: data
    				}
    			}
    			var dg = $(this);
    			var opts = dg.datagrid('options');
    			var pager = dg.datagrid('getPager');
    			pager.pagination({
    				onSelectPage:function(pageNum, pageSize){
    					opts.pageNumber = pageNum;
    					opts.pageSize = pageSize;
    					pager.pagination('refresh',{
    						pageNumber:pageNum,
    						pageSize:pageSize
    					});
    					dg.datagrid('loadData',data);
    				}
    			});
    			if (!data.originalRows){
    				data.originalRows = (data.rows);
    			}
    			var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
    			var end = start + parseInt(opts.pageSize);
    			data.rows = (data.originalRows.slice(start, end));
    			return data;
    		}
    		
    		$(function(){
   
    			
    			 var AjaxURL="<%=path%>/admin/group_getGroupList.action";
            	 $.ajax({
                 	url:AjaxURL,
                 	 type:"post",
                 	 datatype:"json",
                 	success:function(data){ 
                 		 var json = eval($.parseJSON(data)); //数组
                 		
                 		$('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(json));       		 
                 			
                 		 
                 	},
                 	error:function(data){
                 	}
                 
                 });
            	 var dataslist = '';
            	 function runajax(){
         			$.ajax({
         				url:"<%=basePath%>admin/user_getResults.action",
         				datatype:"json",
         				type:"post",
         				async:"true",
         			}).success(function(data){
         				if(dataslist!=data){
         				if(data.split(":")[1]=='0'){
             				$("#stats").html($("#stats").html()+"<li>"+data+"<li>");
             				}else if(data.split(":")[1]=='1101'){
             					$("#stats").html($("#stats").html()+"<li>"+data+"已下线<li>");
             				}
         				}
         				dataslist = data;
         			}).error();
         		}
         		
         		setInterval(runajax,8000);	
    		});
    	</script>
    </body>
    </html>